//
//  JCCashRecordCell.m
//  Lead
//
//  Created by shouhan on 2018/7/13.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCCashRecordCell.h"
#import "CashRecordModel.h"
@interface JCCashRecordCell()

@property (nonatomic, strong) UILabel * lastNumberLabel;

@property (nonatomic, strong) UILabel * lastNumber;//尾号

@property (nonatomic, strong) UILabel * moneyLabel;

@property (nonatomic, strong) UILabel * moneyState;//

@property (nonatomic, strong) UILabel * timeLabel; // 时间



@end

@implementation JCCashRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}


+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView
{
    static NSString * cellIndentfile = @"JCCashRecordCell";
    JCCashRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[JCCashRecordCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (void)initUI{

    self.lastNumberLabel = [UILabel new];
    self.lastNumberLabel.text = @"尾号";
    self.lastNumberLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.lastNumberLabel.font = KSHSystemFont(16);
    [self.contentView addSubview:self.lastNumberLabel];
    
    self.lastNumber = [UILabel new];
    self.lastNumber.textColor = [UIColor colorWithHexString:@"#333333"];
    self.lastNumber.font = KSHSystemFont(16);
    [self.contentView addSubview:self.lastNumber];
    
    self.timeLabel = [UILabel new];
    self.timeLabel.textColor = [UIColor colorWithHexString:@"#6d6d6d"];
    self.timeLabel.font = KSHSystemFont(15);
    [self.contentView addSubview:self.timeLabel];
    
    self.moneyLabel = [UILabel new];
    self.moneyLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    self.moneyLabel.font = KSHSystemFont(15);
    [self.contentView addSubview:self.moneyLabel];
    
    self.moneyState = [UILabel new];
    self.moneyState.textColor = [UIColor colorWithHexString:@"#FF0234"];
    self.moneyState.font = KSHSystemFont(15);
    [self.contentView addSubview:self.moneyState];
}


- (void)layoutIfNeeded{
    [super layoutIfNeeded];
    
    [self.lastNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView).offset(__I6Width(15));
        
    }];
    
    [self.lastNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lastNumberLabel);
        make.left.equalTo(self.lastNumberLabel.mas_right).offset(8);
    }];

    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lastNumberLabel);
        make.right.equalTo(self.contentView).offset(-__I6Width(15));
    }];

    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lastNumberLabel.mas_left);
        make.top.equalTo(self.lastNumberLabel.mas_bottom).offset(15);
    }];

    [self.moneyState mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.timeLabel);
        make.right.equalTo(self.moneyLabel.mas_right);
    }];
    
}

- (void)setModel:(CashRecordModel *)model{
    _model = model;
    self.lastNumber.text = [model.card_no substringWithRange:NSMakeRange(model.card_no.length-4, 4)];
    self.moneyLabel.text = [NSString stringWithFormat:@"¥%@",model.amount];
    self.timeLabel.text = model.trade_date;
    self.moneyState.text = model.trade_status;
}



@end
